/**
 * 
 */
package com.ms.service.module.account.db;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.xpec.c4.db.model.basic.BasicModel;
import com.xpec.c4.game.utility.GameUtility;

/**
 * @author TW15010
 *
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "tcp_proxy_group_list")
public class TcpProxyServerGroupListModel extends BasicModel {
	private static final long serialVersionUID = 2389312532165854797L;

	// proxy 的類型
	public static final int PROXY_TYPE_MAINTAIN = 1;
	public static final int PROXY_TYPE_DEFAULT = 2;
	public static final int PROXY_TYPE_FORMAL = 3;
	
	/**
	 * db id
	 */
	private int id;
	
	/**
	 * proxy 清單<br>
	 * format: com.ms.service.module.account.db.ProxyList<br>
	 * 存在DB裡面的範例JsonString:<br>
	 * {"ragularProxyList":["127.0.0.1:9527","127.0.0.1:9527"],"problemProxyList":[]}
	 */
	private String proxyList;
	
	/**
	 * proxy group 的備註
	 */
	private String description;
	
	/**
	 * proxy 的類型
	 */
	private int proxyType;
	
	/**
	 * 國別
	 */
	private String country;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name="proxyList" , columnDefinition="VARCHAR(2048)")
	public String getProxyList() {
		return proxyList;
	}

	public void setProxyList(String proxyList) {
		this.proxyList = proxyList;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getProxyType() {
		return proxyType;
	}

	public void setProxyType(int proxyType) {
		this.proxyType = proxyType;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}
	
	/**
	 * 判斷是否一樣，description的部分不會被判斷
	 * @param model
	 * @return
	 */
	public boolean equals(TcpProxyServerGroupListModel model){
		if(this.id != model.getId()) return false;
		if(this.proxyType != model.getProxyType()) return false;
		if(!this.proxyList.equals(model.getProxyList())) return false;
		if(!GameUtility.safeStringEquals(this.country, model.getCountry())) return false;
		
		return true;
	}
	
	/**
	 * 判斷自己是否是合法proxyType
	 * @return
	 */
	public boolean LegalProxyType(){
		if(proxyType != PROXY_TYPE_MAINTAIN && proxyType != PROXY_TYPE_DEFAULT && proxyType != PROXY_TYPE_FORMAL)
			return false;
		else return true;
		
	}
	
}
